package com.tiku.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tiku.common.ResultJson;
import com.tiku.controller.DTO.ChooseExamDTO;
import com.tiku.entity.CourseCategories;
import com.tiku.entity.ProfessionCategories;
import com.tiku.entity.SingleSubjectQuestionBanks;
import com.tiku.mapper.SingleSubjectQuestionBanksMapper;
import com.tiku.service.CourseCategoriesService;
import com.tiku.service.ProfessionCategoriesService;
import com.tiku.mapper.ProfessionCategoriesMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 *
 */
@Service
public class ProfessionCategoriesServiceImpl extends ServiceImpl<ProfessionCategoriesMapper, ProfessionCategories>
    implements ProfessionCategoriesService{


    @Autowired
    private ProfessionCategoriesMapper mapper;

    @Autowired
    private CourseCategoriesService  categoriesService;

    @Autowired
    private SingleSubjectQuestionBanksMapper subjectQuestionBanksMapper;
    @Override
    public ResultJson getExaminationList(String examId) {
        List<ProfessionCategories> professionCategories = mapper.selectList(new LambdaQueryWrapper<>(ProfessionCategories.class).eq(ProfessionCategories::getTkProductTradeId, examId));
        return ResultJson.success(professionCategories) ;
    }

    @Override
    public ResultJson getChooseExam() {
        List<CourseCategories> list = categoriesService.list();

        for (CourseCategories courseCategories : list) {
            ChooseExamDTO examDTO=new ChooseExamDTO();
            examDTO.setCourseCategories(courseCategories);

            String id = courseCategories.getId();
            List<ProfessionCategories> list1 = list(new LambdaQueryWrapper<>(ProfessionCategories.class).eq(ProfessionCategories::getTkProductTradeId, id));

            for (ProfessionCategories professionCategories : list1) {
                List<SingleSubjectQuestionBanks> singleSubjectQuestionBanks = subjectQuestionBanksMapper.selectList(new LambdaQueryWrapper<>(SingleSubjectQuestionBanks.class).
                        eq(SingleSubjectQuestionBanks::getProfessionCategoriesId, professionCategories.getId()));
               professionCategories.setSsqbId(singleSubjectQuestionBanks.get(0).getId());

            }

            courseCategories.setContent(list1);

        }
        return ResultJson.success(list);


    }
}




